package com.sg.business.commons.labelprovider.work;

import com.mobnut.commons.util.file.FileUtil;
import com.mobnut.db.model.PrimaryObject;
import com.sg.business.commons.labelprovider.linestyle.LineStyleHtmlLabel;
import com.sg.business.commons.ui.viewer.WorkContentProvider;
import com.sg.business.model.Work;
import com.sg.business.resource.BusinessResource;

public class MarkHtmlLabel extends LineStyleHtmlLabel {

	@Override
	public String getHtmlText(PrimaryObject work) {
		Object mark = work.getValue(WorkContentProvider.F_CACHE_MARK);
		String selectbarUrl = null;
		if (WorkContentProvider.MARK_DELAY.equals(mark)) {
			selectbarUrl = FileUtil.getImageURL(
					BusinessResource.IMAGE_FLAG_RED_24,
					BusinessResource.PLUGIN_ID, BusinessResource.IMAGE_FOLDER);
		} else if (WorkContentProvider.MARK_WARRING.equals(mark)) {
			selectbarUrl = FileUtil.getImageURL(
					BusinessResource.IMAGE_ALERT_24,
					BusinessResource.PLUGIN_ID, BusinessResource.IMAGE_FOLDER);
		} else {
			String userId = getContext().getAccountInfo().getConsignerId();
			if (((Work) work).isMarked(userId)) {
				selectbarUrl = FileUtil.getImageURL(
						BusinessResource.IMAGE_MARK_24,
						BusinessResource.PLUGIN_ID,
						BusinessResource.IMAGE_FOLDER);
			}
		}

		StringBuffer sb = new StringBuffer();
		if (selectbarUrl != null) {
			String selectbar = "<img src='" //$NON-NLS-1$
					+ selectbarUrl
					+ "' style='border-style:none;position:absolute; left:0; top:4; display:block;' width='16' height='16' />"; //$NON-NLS-1$
			sb.append(selectbar);
		}

		return sb.toString();
	}

}
